﻿@{
    Layout = "~/Shared/Layouts/_Layout.cshtml";
    Page.Title = "Почетна";
    
    var db = Database.Open("VirtualeShop");   
    var sqlSelect = "SELECT * FROM Products " + 
                    "INNER JOIN Settings ON Products.ProductID = Settings.featuredProduct";
  
    var product = db.QuerySingle(sqlSelect);
}

@if (product != null)
{   
    <h1 class="homePageHeading">Препорачани производи</h1>
    <div id="featuredProductImage">      
        <p>@Products.ShowProductImage(product.productID.ToString())</p>
    </div>
    <div id="featuredProductDetails">
        <a href="/ProductDetails/@product.productID">
            <h2>@product.title</h2>
        </a>
        <p>
            @product.description
        </p>
        <p class="price">
            £@product.price
        </p>
        <p>
            <a href="/ProductDetails/@product.productID" class="detailsButton">
                Повеќе...
            </a>
        </p>
    </div>
}

@{
    sqlSelect = "SELECT TOP 4 COUNT(productID) AS productCount, productId " + 
                "FROM OrderItems GROUP BY productID ORDER BY productCount DESC";
    var mostPopular = db.Query(sqlSelect);
}
@if (mostPopular.Count() > 0)
{
    <div id="popularProducts">
        <h1 class="homePageHeading">Најпопуларни производи</h1>
        <marquee style="width: auto" behavior="alternate" direction="left" scrollamount="1" scrolldelay="30" truespeed="true" onmouseover="this.stop()" onmouseout="this.start()">
        <ul id="popularProductsList">
            @foreach (var item in mostPopular) {
                <li>
                    <a href="/ProductDetails/@item.productID" class="detailsButton">
                        @Products.ShowProductThumbnail(item.productID.ToString())
                    </a>
                </li>
            }
        </ul>
        </marquee>
    </div>
}